package effective_java.universal;

import java.util.Arrays;

public class Test02 {
    private static Integer i;

    public static void main(String[] args) {
//        boxingVar();
        tooMuchUnboxing();
    }

    private static void boxingVar() {
        // java.lang.NullPointerException
        // cause by: boxing variable 'i' is subjected to unboxing conversion, fix it by change 'Integer' to 'int'
        if (i == 42) {
            System.out.println("eq");
        } else {
            System.out.println("not eq");
        }
    }

    private static void tooMuchUnboxing() {
        Long sum = 0L;// slow
//        long sum = 0L;// faster than 'Long', reduce process of unboxing
        for (int j = 0; j < Integer.MAX_VALUE; j++) {
            sum += j;
        }
        System.out.println(sum);
    }
}
